package backs.bean;

import backs.JSONChater.MyJSONSend;
import backs.bl.UserBL;

public class Message
{
    public int type,groupID,userID;
    public String message;
    public User user;
    public boolean notHandled=true;
    public String backMessage="";
    public Message(int type,int groupId,int userId,String message)
    {
        this.type=type;
        this.groupID=groupId;
        this.userID=userId;
        this.user= UserBL.getUser(userID);
        this.message=message;
    }

    public Message(int userId,String message)
    {
        this.type=1;
        this.groupID=0;
        this.userID=userId;
        this.user= UserBL.getUser(userID);
        this.message=message;
    }

    public void sendBack(String message)
    {
        if(this.type==1)
        {
            MyJSONSend.sendPrivateMessage(user.id,message);
        }
        if(this.type==2)
        {
            MyJSONSend.sendGroupMessage(groupID,message);
        }
        if(this.type==3)
        {
            MyJSONSend.sendDiscussMessage(userID,message);
        }
    }

    public void sendBack()
    {
        if(backMessage!=null&&message.length()>0) sendBack(backMessage);
    }

    public int getPrivateAsGroupID()
    {
        if(this.type==1) return this.userID;
        return this.groupID;
    }
}
